import {
  tasksList,
  startTasks,
  tasksInfo,
  uploadTasks,
  saveTasks,
  updateTasks,
  process,
  delrec,
  approveRecord,
  delTasks,
  delfirerec
} from '@/api/Tasks'

export default defineStore('useTasks', {
  state: () => ({}),
  getters: {},
  actions: {
    //行政许可任务列表
    async getTasksList(params) {
      let url = $globalRequestUrl({
        url: tasksList,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    //任务开始检查
    async startTasks(id) {
      let url = $globalRequestUrl({
        url: startTasks + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },
    //获取任务信息
    async taskInfo(id) {
      let url = $globalRequestUrl({
        url: tasksInfo + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //提交任务检查
    async uploadTask(params) {
      let url = $globalRequestUrl({
        url: uploadTasks,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    //添加任务检查
    async saveTasks(params) {
      let url = $globalRequestUrl({
        url: saveTasks,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //修改任务检查
    async updateTasks(params) {
      let url = $globalRequestUrl({
        url: updateTasks,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'PUT' })
        return rep
      } catch (error) {
        return error
      }
    },

    //处理任务信息
    async process(params) {
      let url = $globalRequestUrl({
        url: process,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    //送达回证签字后的上传
    async delrec(params) {
      let url = $globalRequestUrl({
        url: delrec,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    //消防送达回证签字后的上传删除
    async delfirerec(params) {
      let url = $globalRequestUrl({
        url: `${delfirerec}/${params.type}/${params.taskId}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },
    //审批记录
    async approveRecord(id) {
      let url = $globalRequestUrl({
        url: approveRecord + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //删除行政许可任务
    async delTasks(id) {
      let url = $globalRequestUrl({
        url: delTasks + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'DELETE' })
        return rep
      } catch (error) {
        return error
      }
    },
  },
})
